//
//  ifSwitch.swift
//  swiftStudy
//
//  Created by unisedu on 16/4/1.
//  Copyright © 2016年 CaoFei. All rights reserved.
//

import UIKit
/*
本讲主要介绍如下的内容：1. if条件语句的语法格式、2. switch语句的语法格式、3. break和fallthrough关键字、4. 区间条件、5. 元组条件、6. 值绑定、7. where子句
*/
class ifSwitch: NSObject {
    func show(){
        let vegetable = "red pepper"
        switch vegetable {
        case "celery":
            let vegetableComment = "Add some raisins and make ants on a log."
            //无条件执行下一条case
            fallthrough
        case "cucumber", "watercress":
            let vegetableComment = "That would make a good tea sandwich."
        case let x where x.hasSuffix("pepper"):
            let vegetableComment = "Is it a spicy \(x)?"
        default:
            let vegetableComment = "Everything tastes good in soup."
        }
        
        
        let ve = 20
        let v = 30
        switch ve {
        case 20:
            print(20)
            if v == 30
            {
                break
            }
            print("abc")
        default:
            print("default")
        }
        
        
        let price = 5000
        
        switch price {
        case 0:
            print("abc")
        case 1...10:
            print("abc")
        case 11...5000:
            print("aaaaaaa")
        default:
            print("default")
        }
        
        
        switch price {
        case 0:
            print("abc")
        case 1...10:
            print("abc")
        case 11...5000:
            print("aaaaaaa")
        default:
            print("default")
        }
        
        
        let str = "Hello, playground"
        let str1="asdf"
        let sss=str+str1
        debugPrint(sss)
        let 单精度浮点:Float=4
        let label = "The width is"
        let width = 94
        let widthLabel = label + String(width)
        debugPrint(widthLabel)
        let apples=3
        let oranges=5
        let appleSummary="I have \(单精度浮点)apples."
        debugPrint(apples,oranges,appleSummary)
        var shoppingList=["aaa","bbb","ccc"]
        shoppingList[1]="bottle of aaa"
        debugPrint(shoppingList)
        
        
        var occupations=["asdf":"as","asd":"sff"]
        occupations["asdf"]="public relations"
        debugPrint(occupations)
        
        let individualScores = [75, 43, 103, 87, 12]
        var teamScore = 0
        for score in individualScores {
            if score > 50 {
                teamScore += 3
            } else {
                teamScore += 1
            }
        }
        debugPrint(teamScore)
        
        let a=[23,43,54,45,23]
        var b=0
        for addd in a{
            if  addd>50{
                b++
            }else{
                b--;
            }
        }
        debugPrint(b)
        
        
        var optionalString: String? = "Hello"
        optionalString = nil
        debugPrint(optionalString)
        let optionalName: String? = "John Appleseed"
        //optionalName = nil
        
        
        var greeting = "Hello!"
        if let name = optionalName {
            greeting = "Hello, \(name)"
        }else{
            greeting = "Hello"
        }

    }
}
